package com.pureut.storage.service.impl;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.storage.domain.PublicMaterial;
import com.pureut.storage.domain.WmsStockInfo;
import com.pureut.storage.dto.*;
import com.pureut.storage.mapper.PublicMaterialMapper;
import com.pureut.storage.mapper.WarehouseMapper;
import com.pureut.storage.mapper.WmsStockInfoMapper;
import com.pureut.storage.service.WmsStockInfoService;
import com.pureut.storage.util.MessageRemindMqUtil;
import com.pureut.storage.util.UnitUtil;
import com.pureut.storage.vo.*;
import com.sale.common.core.constant.CacheNames;
import com.sale.common.core.utils.StringUtils;
import com.sale.common.dict.utils.DictUtils;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.common.redis.utils.CacheUtils;
import com.sale.common.redis.utils.RedisUtils;
import com.sale.common.satoken.utils.LoginHelper;
import com.sale.order.api.RemoteCustomerService;
import com.sale.order.api.RemoteSupplierService;
import com.sale.system.api.*;

import com.sale.system.api.domain.*;
import com.sale.system.api.domain.dto.SysTheAlarmDto;
import com.sale.system.api.domain.vo.SysWorkbenchMessageVo;
import com.sale.system.api.model.MaterialUnitDto;
import lombok.RequiredArgsConstructor;
import net.sf.jsqlparser.expression.StringValue;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 库存实现层
 *
 * @author: CM
 * @date: 2023/1/6  13:50
 */
@Service
@RequiredArgsConstructor
public class WmsStockInfoServiceImpl extends ServiceImpl<WmsStockInfoMapper,WmsStockInfo> implements WmsStockInfoService {

    /**
     * 库存mapper
     */
    private final WmsStockInfoMapper wmsStockInfoMapper;

    /**
     * 单位Mapper
     */
    @DubboReference
    RemoteUnitService remoteUnitService;

    @DubboReference
    RemoteSysSupplierService remoteSupplierService;

    @DubboReference
    RemoteSysCustomerService remoteCustomerService;

    @DubboReference
    RemoteMaterialService remoteMaterialService;

    /**
     * 公共物料
     */
    private final PublicMaterialMapper publicMaterialMapper;

    @DubboReference
    RemoteWorkbenchMessageService remoteWorkbenchMessageService;

    /**
     * 仓库
     */
    private final WarehouseMapper warehouseMapper;

    private final UnitUtil unitUtil;


//    /**
//     * 生产领料
//     */
//    @Resource
//    private StockOutInfoDetailMapper stockOutInfoDetailMapper;
//
//    /**
//     * 销售发货
//     */
//    @Resource
//    private PickingSaleDetailMapper pickingSaleDetailMapper;
//
//    /**
//     * 返工出库
//     */
//    @Resource
//    private PickingCompleteDetailMapper pickingCompleteDetailMapper;
//
//    /**
//     * 采购退货
//     */
//    @Resource
//    private PickingPurchaseDetailMapper pickingPurchaseDetailMapper;
//
//    /**
//     * 其他出库
//     */
//    @Resource
//    private PickingRestDetailMapper pickingRestDetailMapper;
//
//    /**
//     * 采购入库
//     */
//    @Resource
//    private PurchaseReceiptDetailMapper purchaseReceiptDetailMapper;
//
//    /**
//     * 销售退货
//     */
//    @Resource
//    private SalesReturnDetailMapper salesReturnDetailMapper;
//
//    /**
//     * 生产退料
//     */
//    @Resource
//    private ProductionMaterialReturnDetailMapper productionMaterialReturnDetailMapper;
//
//    /**
//     * 完工入库
//     */
//    @Resource
//    private WipCompletionDetailMapper wipCompletionDetailMapper;
//
//    /**
//     * 其他入库
//     */
//    @Resource
//    private MiscellaneousReceiptDetailMapper miscellaneousReceiptDetailMapper;
//
//    /**
//     * 库存日志
//     */
//    @Resource
//    private OutboundLogMapper outboundLogMapper;
//

//
//    /**
//     * 调拨单信息
//     */
//    @Resource
//    private AllotManagementDetailMapper allotManagementDetailMapper;
//
//    /**
//     * 盘点物料明细
//     */
//    @Resource
//    private CheckManagementMaterialDetailMapper checkManagementMaterialDetailMapper;
//
//    /**
//     * 根据母卷号码查询库存信息
//     *
//     * @param masterVolumeNumber
//     * @return
//     */
//    @Override
//
//    public MasterVolumeDto selectMasterVolumeList(String masterVolumeNumber) {
//
//        // 根据母卷号码查询库存信息
//        MasterVolumeDto masterVolumeDto = wmsStockInfoMapper.selectMasterVolumeList(masterVolumeNumber);
//        if (masterVolumeDto == null) {
//            throw new GlobalException("库存不存在该母卷号码信息");
//        }
//        return masterVolumeDto;
//    }
//
//    /**
//     * 根据母卷号码修改库存的卷长
//     *
//     * @param wmsStockInfoVo
//     * @return
//     */
//    @Override
//    public int updateStockInfoById(WmsStockInfoVo wmsStockInfoVo) {
//        return wmsStockInfoMapper.updateStockInfoById(wmsStockInfoVo);
//    }
//
//    /**
//     * 远程调用 删除库存信息
//     *
//     * @param truncationMasterVolumeNumber
//     * @return
//     */
//    @Override
//    public int deleteStockInfoById(String truncationMasterVolumeNumber) {
//        return wmsStockInfoMapper.deleteStockInfoById(truncationMasterVolumeNumber);
//    }
//
//    /**
//     * 根据物料编码和批次号获取仓库信息
//     *
//     * @param wmsStockInfoVo
//     * @return
//     */
//    @Override
////    @DataScope(deptAlias = "d")
//    public List<WmsStockInfoDto> getStockInfo(WmsStockInfoVo wmsStockInfoVo) throws ParseException {
//        List<WmsStockInfoDto> stockInfoList = wmsStockInfoMapper.getStockInfoList(wmsStockInfoVo);
//        if (stockInfoList.size() < 1) {
//            return new ArrayList<>();
//        }
//        for (WmsStockInfoDto entity : stockInfoList) {
//            //获取入库时间
//            Date wsiReveiveTime = entity.getWsiReveiveTime();
//            //获取复检天数
//            int materialInspection = entity.getMaterialInspection();
//
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(wsiReveiveTime);
//            calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
//            Date time = calendar.getTime();
//            //判断当前时间是否大于添加天数之后的时间
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String time2 = simpleDateFormat.format(time);
//            String time3 = simpleDateFormat.format(new Date());
//            if (time2.compareTo(time3) > 0) {
//                entity.setIsOutTime(2);
//                entity.setMaturityTime(time);
//            } else {
//                entity.setMaturityTime(time);
//                entity.setIsOutTime(1);
//            }
//        }
//        return stockInfoList;
//    }
//
//    /**
//     * 根据物料号码修改单据状态
//     *
//     * @param wmsStockInfoVo
//     * @return
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean updateStatus(WmsStockInfoVo wmsStockInfoVo) {
//
//        List<String> materialNumberList = wmsStockInfoVo.getMaterialNumberList();
//
//        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));
//        for (WmsStockInfo entity : wmsStockInfoList) {
//            entity.setWsiMaterialStatus(wmsStockInfoVo.getWsiMaterialStatus());
//        }
//        return updateBatchById(wmsStockInfoList);
//    }
//
//    /**
//     * 查询仓库信息（品质检验冻结查询）
//     *
//     * @param qualityFreezeVo
//     * @return
//     */
//    @Override
//    public List<WmsStockInfoDto> getFreezeStockList(QualityFreezeVo qualityFreezeVo) {
//        if (qualityFreezeVo.getbeginTime() == null && qualityFreezeVo.getEndTime() == null && qualityFreezeVo.getWsiConnectNum() == null && qualityFreezeVo.getWsiMaterialCode() == null && qualityFreezeVo.getWsiMaterialNumber() == null) {
//            List<WmsStockInfoDto> objects = new ArrayList<>();
//            return objects;
//        } else {
//            List<WmsStockInfoDto> freezeStockList = wmsStockInfoMapper.getFreezeStockList(qualityFreezeVo);
//            return freezeStockList;
//        }
//    }
//
//    /**
//     * 仓库状态批量修改
//     *
//     * @param warehouseStatusUpdateVo
//     * @return
//     */
//    @Override
//    public boolean getUpdate(WarehouseStatusUpdateVo warehouseStatusUpdateVo) {
//        List<WmsStockInfo> wmsStockInfoList = null;
//        if (warehouseStatusUpdateVo.getIds() != null) {
//            wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getId, warehouseStatusUpdateVo.getIds()));
//            for (WmsStockInfo entity : wmsStockInfoList) {
////                //获取入库时间
////                Date wsiReveiveTime = entity.getWsiReveiveTime();
////                //获取复检天数
////                List<PublicGoods> publicGoods = publicGoodsMapper.selectList(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, entity.getWsiMaterialCode()));
////                if (publicGoods.size() > 0) {
////                    int materialInspection = publicGoods.get(0).getMaterialInspection();
////
////                    Calendar calendar = Calendar.getInstance();
////                    calendar.setTime(wsiReveiveTime);
////                    calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
////                    Date time = calendar.getTime();
////                    entity.setWsiRecheckDate(time);
////                }
//                entity.setWsiRecheckDate(new Date());
//                if (warehouseStatusUpdateVo.getStatusValue() != 0) {
//                    entity.setWsiMaterialStatus(warehouseStatusUpdateVo.getStatusValue());
//                }
//                if (warehouseStatusUpdateVo.getFreeValue() != null) {
//                    entity.setWsiFreezeInfo(warehouseStatusUpdateVo.getFreeValue());
//                }
//                if (warehouseStatusUpdateVo.getMaterialGradeValue() != 0) {
//                    entity.setWsiMaterialGrade(String.valueOf(warehouseStatusUpdateVo.getMaterialGradeValue()));
//                }
//            }
//        }
//
//        if (warehouseStatusUpdateVo.getMaterialNumberList() != null) {
//            List<String> materialNumberList = warehouseStatusUpdateVo.getMaterialNumberList();
//            wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));
//            for (WmsStockInfo entity : wmsStockInfoList) {
//                if (warehouseStatusUpdateVo.getStatusValue() != 0) {
//                    entity.setWsiMaterialStatus(warehouseStatusUpdateVo.getStatusValue());
//                }
//                if (warehouseStatusUpdateVo.getFreeValue() != null) {
//                    entity.setWsiFreezeInfo(warehouseStatusUpdateVo.getFreeValue());
//                }
//                if (warehouseStatusUpdateVo.getMaterialGradeValue() != 0) {
//                    entity.setWsiMaterialGrade(String.valueOf(warehouseStatusUpdateVo.getMaterialGradeValue()));
//                }
//            }
//        }
//        return updateBatchById(wmsStockInfoList);
//    }
//

    /**
     * 盘点库存汇总
     *
     * @return checkStockVo
     */
    @Override
    public List<WmsStockInfoSumDto> sumStock(CheckStockVo checkStockVo) {
        List<WmsStockInfoSumDto> wmsStockInfoSumDtos = wmsStockInfoMapper.sumStockList(checkStockVo);
        for (WmsStockInfoSumDto wmsStockInfoSumDto : wmsStockInfoSumDtos) {
           // MaterialUnitDto materialUnitDto = remoteUnitService.getUnitByCode(wmsStockInfoSumDto.getWsiMaterialCode());
            //单位集合
            Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();
            //基本单位
            if(unitByCodeToMap.get(wmsStockInfoSumDto.getMaterialUnit()) != null){
                wmsStockInfoSumDto.setMaterialUnit(unitByCodeToMap.get(wmsStockInfoSumDto.getMaterialUnit()).getUnitName());
            }

            //辅助单位
           // wmsStockInfoSumDto.setAuxiliaryUnit(materialUnitDto.getAuxiliaryUnit());

            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + wmsStockInfoSumDto.getTenantId(), wmsStockInfoSumDto.getMaterialId());
            wmsStockInfoSumDto.setAuxiliaryAttribute(statsArray);

//            List<SysAuxiliaryUnitDetail> list = materialUnitDto.getList();
            //定义多单位数量
//            String moreUnit = "";

//            String num = String.valueOf(wmsStockInfoSumDto.getUnitNum());

//            if (list != null && list.size() != 0) {
//
//                for (SysAuxiliaryUnitDetail sysAuxiliaryUnitDetail : list) {
//                    String unitQuantity = sysAuxiliaryUnitDetail.getUnitQuantity();
//                    BigDecimal number1 = new BigDecimal(num);
//                    BigDecimal number2 = new BigDecimal(unitQuantity);
//                    BigDecimal[] bigDecimals = number1.divideAndRemainder(number2);
//                    // 数组的第一个值为商，第二个值为余数
//                    String discuss = bigDecimals[0].toString();
//                    String remainder = bigDecimals[1].toString();
//
//                    //如果直接被整除说明刚好满足当前最大单位
//                    if ("0".equals(remainder)) {
//                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
//                        break;
//                    } else {
//                        if (sysAuxiliaryUnitDetail == list.get(list.size() - 1)) {
//                            moreUnit = moreUnit + remainder + materialUnitDto.getUnitName();
//                        }
//
//                        if ("0".equals(discuss)) {
//                            continue;
//                        }
//                        //没有被整除
//                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
//                        //修改num的值为当前的余数
//                        num = remainder;
//
//                    }
//
//                }
//
//                //如果多单位数量为“”说明不满足其他的辅助单位,只满足最小单位
//                if ("".equals(moreUnit)) {
//                    moreUnit = wmsStockInfoSumDto.getUnitNum() + "" + materialUnitDto.getUnitName();
//                }
//
//            }
//            wmsStockInfoSumDto.setMoreUnitNum(moreUnit);
        }
        return wmsStockInfoSumDtos;
    }


    /**
     * 库存明细列表
     *
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getList(CheckStockVo checkStockVo) {
        List<WmsStockInfoDto> page = wmsStockInfoMapper.getStockList(checkStockVo);
        //客户
        Map<String, String> customerMap = remoteCustomerService.getOpenCustomerFinance();
        //供应商
        Map<String, String> supplierMap = remoteSupplierService.getOpenSupplierFinance();

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        for (WmsStockInfoDto record : page) {
            //单位转换
            String s = unitUtil.unitC(record.getWsiMaterialCode(),
                record.getStockNum(),
                record.getMaterialId(),
                unitByCodeToMap.get(record.getMaterialUnit()).getUnitName());
            record.setUnitConversion(s);
            //类别
            if (record.getWsiMaterialType() == 1) {
                record.setCodingRules("原料");
            } else {
                record.setCodingRules("成品");
            }
            //客户
            if (record.getWsiCustomCode() != null) {
                record.setCustomerName(customerMap.get(record.getWsiCustomCode()));
            }

            //供应商
            if (record.getWsiSupplierCode() != null) {
                record.setSupplierName(supplierMap.get(record.getWsiSupplierCode()));
            }

            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + record.getTenantId(), String.valueOf(record.getMaterialId()));
            record.setAuxiliaryAttribute(statsArray);

            //单位
            if (unitByCodeToMap.get(record.getMaterialUnit()) != null) {
                //String unitName = remoteUnitService.getUnitDataByCode(Long.parseLong(record.getMaterialUnit())).getData().getUnitName();
                record.setMaterialUnitDict(unitByCodeToMap.get(record.getMaterialUnit()).getUnitName());
            }

        }

        return page;
    }

    /**
     * 盘点中物料
     *
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getAllotList(CheckStockVo checkStockVo) {
        List<WmsStockInfoDto> list = wmsStockInfoMapper.getAllotList(checkStockVo);

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        for (WmsStockInfoDto record : list) {

            //单位转换
            String s = unitUtil.unitC(record.getWsiMaterialCode(),
                record.getStockNum(),
                record.getMaterialId(),
                unitByCodeToMap.get(record.getMaterialUnit()).getUnitName());
            record.setUnitConversion(s);

            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + record.getTenantId(), String.valueOf(record.getMaterialId()));
            record.setAuxiliaryAttribute(statsArray);

            //单位
            if (unitByCodeToMap.get(record.getMaterialUnit()) != null) {
                //String unitName = remoteUnitService.getUnitDataByCode(Long.parseLong(record.getMaterialUnit())).getData().getUnitName();
                record.setMaterialUnitDict(unitByCodeToMap.get(record.getMaterialUnit()).getUnitName());
            }

            //获取单据状态字典数据
            List<SysDictData> statusArray = CacheUtils.get(CacheNames.SYS_DICT, "wms_stock_info_status");
            Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

            record.setWsiMaterialStatus(statusMap.get(record.getWsiMaterialStatus()));

        }
        return list;
    }
//
//    /**
//     * 库存新增
//     *
//     * @param wmsStockInfoVo
//     * @return
//     */
//    @Override
//    public boolean add(WmsStockInfoVo wmsStockInfoVo) {
//        WmsStockInfo wmsStockInfo = new WmsStockInfo();
//        BeanUtils.copyProperties(wmsStockInfoVo, wmsStockInfo);
//        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
//        wmsStockInfo.setWsiProducedDate(wmsStockInfoVo.getWsiProducedDate());
//        wmsStockInfo.setWsiReveiveTime(wmsStockInfoVo.getWsiReveiveTime());
//        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
//        wmsStockInfo.setWsiProducedStep(wmsStockInfoVo.getWsiProducedStep());
//        return save(wmsStockInfo);
//    }
//
//    /**
//     * 类别加编码获取仓库数据
//     *
//     * @param materialNumber
//     * @return
//     */
//    @Override
//    public List<WmsStockInfoDto> getDataByCategoryAndCode(String materialNumber) {
//        List<String> numberList = Arrays.asList(materialNumber.split(","));
//
//
//        List<WmsStockInfoDto> stockInfoList = wmsStockInfoMapper.getDataByCategoryAndCode(numberList);
//
//        if (stockInfoList.size() < 1) {
//            throw new GlobalException("未查询到对应的在库物料");
//        }
//
//        for (WmsStockInfoDto entity : stockInfoList) {
//            //获取入库时间
//            Date wsiReveiveTime = entity.getWsiReveiveTime();
//            //获取复检天数
//            int materialInspection = entity.getMaterialInspection();
//
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(wsiReveiveTime);
//            calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
//            Date time = calendar.getTime();
//            //判断当前时间是否大于添加天数之后的时间
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String time2 = simpleDateFormat.format(time);
//            String time3 = simpleDateFormat.format(new Date());
//            if (time2.compareTo(time3) > 0) {
//                entity.setIsOutTime(2);
//                entity.setMaturityTime(time);
//            } else {
//                entity.setIsOutTime(1);
//                entity.setMaturityTime(time);
//            }
//        }
//
//        return stockInfoList;
//    }
//
//    /**
//     * 修正水刺母卷
//     *
//     * @param wmsStockInfoVo
//     * @return
//     */
//    @Override
//    public boolean updateSpunlace(WmsStockInfoVo wmsStockInfoVo) {
//        //通过母卷号码查出库存信息
//        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, wmsStockInfoVo.getWsiMaterialNumber()));
//
//        //修改毛重
//        wmsStockInfo.setWsiGorssWeight(wmsStockInfoVo.getWsiGorssWeight());
//        //修改净重
//        wmsStockInfo.setWsiNetWeight(wmsStockInfoVo.getWsiNetWeight());
//        //修改幅宽
//        wmsStockInfo.setWsiWidth(wmsStockInfoVo.getWsiWidth());
//        //修改卷长
//        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
//        //修改卷径
//        wmsStockInfo.setWsiDiameter(wmsStockInfoVo.getWsiDiameter());
//        //修改厚度
//        wmsStockInfo.setWsiThick(wmsStockInfoVo.getWsiThick());
//        //修改克重
//        wmsStockInfo.setWsiGrawWeight(wmsStockInfoVo.getWsiGrawWeight());
//        //修改接头
//        wmsStockInfo.setWsiJoint(wmsStockInfoVo.getWsiJoint());
//        return updateById(wmsStockInfo);
//    }

    /**
     * 返工出库新增（状态为返工）
     *
     * @param moStockInfoVo
     * @return
     */
    @Override
    public List<MoStockDto> getStockInfoMo(MoStockInfoVo moStockInfoVo) {
        List<MoStockDto> list = wmsStockInfoMapper.getMoStockInfo(moStockInfoVo);
        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        for(MoStockDto entity : list){
            //单位
            entity.setMaterialUnitDict(unitByCodeToMap.get(String.valueOf(entity.getMaterialUnit())).getUnitName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + entity.getTenantId(), String.valueOf(entity.getMaterialId()));
            entity.setAuxiliaryAttribute(statsArray);
        }
        return list;
    }


    /**
     * 采购入库单
     *
     * @param purchaseStockVo
     */
    @Override
    public List<MoStockDto> getPurchase(PurchaseStockVo purchaseStockVo) {
        List<MoStockDto> list = wmsStockInfoMapper.getPurchase(purchaseStockVo);
        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();
        for (MoStockDto moStockDto : list) {
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + moStockDto.getTenantId(), String.valueOf(moStockDto.getMaterialId()));
            moStockDto.setAuxiliaryAttribute(statsArray);
            if (moStockDto.getMaterialUnit() != null) {
//                String unitName = remoteUnitService.getUnitDataByCode(moStockDto.getMaterialUnit()).getData().getUnitName();
                moStockDto.setMaterialUnit(moStockDto.getMaterialUnit());
                moStockDto.setMaterialUnitDict(unitByCodeToMap.get(String.valueOf(moStockDto.getMaterialUnit())).getUnitName());
            }
            if (moStockDto.getMaterialCategory().equals("1")) {
                moStockDto.setMaterialCategoryDict("原料");
            } else {
                moStockDto.setMaterialCategoryDict("成品");
            }

        }
        return list;
    }
//
//    /**
//     * 根据物料编码获取该物料在仓库中的净重之和(feign调用)
//     *
//     * @param materialCode
//     * @return
//     */
//    @Override
//    public String getSum(String materialCode) {
//
//        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialCode, materialCode).eq(WmsStockInfo::getWsiMaterialStatus, 2));
//        BigDecimal bigDecimal = new BigDecimal(0);
//        for (WmsStockInfo entity : wmsStockInfoList) {
//            bigDecimal = bigDecimal.add(new BigDecimal(String.valueOf(entity.getWsiNetWeight())));
//        }
//        return bigDecimal.toString();
//    }
//
//
//    /**
//     * 根据物料编码获取库存重量（feign调用 委外入库页面使用）
//     *
//     * @param materialCode
//     * @return
//     */
//    @Override
//    public double getStockWeight(String materialCode) {
//
//        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialCode, materialCode));
//        BigDecimal bigDecimal = new BigDecimal(0);
//        for (WmsStockInfo entity : wmsStockInfoList) {
//            bigDecimal = bigDecimal.add(new BigDecimal(String.valueOf(entity.getWsiNetWeight())));
//        }
//        return Double.parseDouble(bigDecimal.toString());
//    }
//
//    /**
//     * 根据物料号码修改库存状态为冻结
//     *
//     * @param materialNumber
//     */
//    @Override
//    public void updateStatusThaw(String materialNumber) {
//        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, materialNumber));
//        if (wmsStockInfo != null) {
//            wmsStockInfo.setWsiFreezeInfo("1");
//            updateById(wmsStockInfo);
//        }
//    }
//
//    /**
//     * 修改库存状态更新为“在库”
//     *
//     * @param updateStatusVo
//     * @return
//     */
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean updateStockStatus(UpdateStatusVo updateStatusVo) {
//
//        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, updateStatusVo.getMaterialNumberList()));
//        for (WmsStockInfo entity : wmsStockInfoList) {
//            entity.setWsiMaterialStatus(2);
//        }
//        return updateBatchById(wmsStockInfoList);
//    }
//
//    /**
//     * 查询基础信息（feign调用 物料追溯页面使用）
//     *
//     * @param wsiCategory, wsiMaterialNumber
//     * @return
//     */
//    @Override
//    public List<RetrospectManageDto> getRetrospectManageList(Long wsiCategory, String wsiMaterialNumber) {
//
//        // 类别
//        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
//        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 物料等级
//        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
//        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 库存状态
//        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
//        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 冻结标识
//        List<SysDictData> freezeInfo = DictUtils.getDictCache("wms_stock_info_freeze_info");
//        Map<String, String> freezeInfoMap = freezeInfo.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        List<RetrospectManageDto> list = new ArrayList<>();
//
//        // 库存表
//        List<RetrospectManageDto> retrospectManageList = wmsStockInfoMapper.getRetrospectManageList(wsiCategory, wsiMaterialNumber);
//
//        if (retrospectManageList.size() > 0) {
//            for (RetrospectManageDto retrospectManageDto : retrospectManageList) {
//                AjaxResult ajaxResult = feignService.selectCodingRulesById(retrospectManageDto.getWsiMaterialType());
//                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
//
//                // 数据字典
//                retrospectManageDto.setWsiCategoryDict(qualityCategoryMap.get(retrospectManageDto.getWsiCategory()));
//                retrospectManageDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(retrospectManageDto.getWsiMaterialGrade()));
//                retrospectManageDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(retrospectManageDto.getWsiMaterialStatus()));
//                retrospectManageDto.setWsiFreezeInfoDict(freezeInfoMap.get(retrospectManageDto.getWsiFreezeInfo()));
//                retrospectManageDto.setWsiMaterialTypeDict(data.getCodingRules());
//                list.add(retrospectManageDto);
//            }
//        } else {
//            // 库存日志表
//            List<RetrospectManageDto> retrospectManageInfo = wmsStockInfoMapper.selectRetrospectManageInfo(wsiCategory, wsiMaterialNumber);
//            for (RetrospectManageDto retrospectManageDto : retrospectManageInfo) {
//                AjaxResult ajaxResult = feignService.selectCodingRulesById(retrospectManageDto.getWsiMaterialType());
//                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
//
//                // 数据字典
//                retrospectManageDto.setWsiCategoryDict(qualityCategoryMap.get(retrospectManageDto.getWsiCategory()));
//                retrospectManageDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(retrospectManageDto.getWsiMaterialGrade()));
//                retrospectManageDto.setWsiMaterialStatusDict("已出库");
//                retrospectManageDto.setWsiFreezeInfoDict(freezeInfoMap.get(retrospectManageDto.getWsiFreezeInfo()));
//                retrospectManageDto.setWsiMaterialTypeDict(data.getCodingRules());
//                list.add(retrospectManageDto);
//            }
//        }
//
//
//        return list;
//    }
//
//    /**
//     * 查询同批次物料 （feign调用 物料追溯页面使用）
//     *
//     * @param wsiMaterialNumber 根据物料号码查询
//     * @return
//     */
//    @Override
//    public List<RetrospectMaterialDto> getRetrospectMaterialList(String wsiMaterialNumber) {
//
//        // 出库总集合
//        List<RetrospectMaterialDto> list = new ArrayList<>();
//        // 物料等级
//        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
//        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 库存状态
//        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
//        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 查询物料批次号 库存表
//        RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);
//
//        // 查询物料批次号 库存日志表
//        RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);
//
//        if (retrospectMaterialList != null) {
//
//            List<RetrospectMaterialDto> list1 = new ArrayList<>();
//            List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//            for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                // 物料号码
//                retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                // 净重
//                retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                // 库存状态
//                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                list1.add(retrospectMaterialDto);
//            }
//
//            List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//            for (OutboundLog outboundLog : outboundLogs) {
//                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                // 物料号码
//                retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                // 净重
//                retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                // 库存状态
//                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                list1.add(retrospectMaterialDto);
//            }
//            list.addAll(list1);
//
//        } else {
//
//            List<RetrospectMaterialDto> list1 = new ArrayList<>();
//            List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//            for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                // 物料号码
//                retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                // 净重
//                retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                // 库存状态
//                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                list1.add(retrospectMaterialDto);
//            }
//
//            List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//            for (OutboundLog outboundLog : outboundLogs) {
//                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                // 物料号码
//                retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                // 净重
//                retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                // 库存状态
//                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                list1.add(retrospectMaterialDto);
//            }
//            list.addAll(list1);
//        }
//
//        ArrayList<RetrospectMaterialDto> collect = list.stream().collect(
//                Collectors.collectingAndThen(
//                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(RetrospectMaterialDto::getWsiMaterialNumber))),
//                        ArrayList::new));
//
//        // 去除重复数据
//        return collect;
//    }
//
//    /**
//     * 产品追溯 同批次物料
//     *
//     * @param wsiMaterialNumber 根据物料号码查询
//     * @return
//     */
//    @Override
//    public List<RetrospectMaterialDto> getRetrospectProductList(String codingType, String wsiMaterialNumber) {
//
//        // 出库总集合
//        List<RetrospectMaterialDto> list = new ArrayList<>();
//        // 物料等级
//        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
//        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 库存状态
//        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
//        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//
//        // 如果是成品
//        if (codingType.equals("1")) {
//
//            // 查询物料批次号 库存表
//            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);
//
//            // 查询物料批次号 库存日志表
//            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);
//
//            if (retrospectMaterialList != null) {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//
//            } else {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                if (wmsStockInfos.size() > 0) {
//                    for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                        RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                        // 物料号码
//                        retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                        // 净重
//                        retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                        // 库存状态
//                        retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                        retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                        retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                        retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                        list1.add(retrospectMaterialDto);
//                    }
//
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//            }
//
//        }
//        // 如果是母卷
//        if (codingType.equals("2")) {
//            // 查询物料批次号 库存表
//            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);
//
//            // 查询物料批次号 库存日志表
//            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);
//
//            if (retrospectMaterialList != null) {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//
//            } else {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//            }
//        }
//
//        // 如果是小卷
//        if (codingType.equals("3")) {
//            AjaxResult ajaxResult1 = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
//            RollPackingHistoryDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), RollPackingHistoryDto.class);
//
//            // 查询物料批次号 库存表
//            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(data1.getMasterVolumeNumber());
//
//            // 查询物料批次号 库存日志表
//            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(data1.getMasterVolumeNumber());
//
//            if (retrospectMaterialList != null) {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//
//            } else {
//
//                List<RetrospectMaterialDto> list1 = new ArrayList<>();
//                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//
//                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
//                for (OutboundLog outboundLog : outboundLogs) {
//                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
//                    // 物料号码
//                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
//                    // 净重
//                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
//                    // 库存状态
//                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
//                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
//                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
//                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
//                    list1.add(retrospectMaterialDto);
//                }
//                list.addAll(list1);
//            }
//        }
//
//        ArrayList<RetrospectMaterialDto> collect = list.stream().collect(
//                Collectors.collectingAndThen(
//                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(RetrospectMaterialDto::getWsiMaterialNumber))),
//                        ArrayList::new));
//        // 去除重复数据
//        return collect;
//    }
//
//    /**
//     * 物料履历
//     *
//     * @param wsiMaterialNumber
//     * @return
//     */
//    @Override
//    public List<MaterialResumeDto> MaterialResumeList(Long wsiCategory, String wsiMaterialNumber) {
//
//        List<MaterialResumeDto> list = new ArrayList<>();
//
//        // 当类型为原料
//        if (wsiCategory == 1) {
//            // 来料打印
//            List<MaterialResumeDto> materialResumeDtoList = new ArrayList<>();
//            List<MaterialResumeDto> materialResumeDtos = wmsStockInfoMapper.getIncomingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : materialResumeDtos) {
//                materialResumeDto.setJobTypeDict("采购打印");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                materialResumeDtoList.add(materialResumeDto);
//
//            }
//            // 采购入库
//            List<MaterialResumeDto> purchasePersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> purchasePersonalDetails = wmsStockInfoMapper.getPurchasePersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : purchasePersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码/批次入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                purchasePersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 生产退料
//            List<MaterialResumeDto> productionReturnPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> productionReturnPersonalDetails = wmsStockInfoMapper.getProductionReturnPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : productionReturnPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                productionReturnPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 其他入库
//            List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                otherWarehousingPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 生产领料
//            List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                pickingPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 委外发货
//            List<MaterialResumeDto> outsourcingShipmentPersonalList = new ArrayList<>();
//            List<MaterialResumeDto> outsourcingShipmentPersonal = wmsStockInfoMapper.getOutsourcingShipmentPersonal(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : outsourcingShipmentPersonal) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                outsourcingShipmentPersonalList.add(materialResumeDto);
//            }
//
//            // 采购退货
//            List<MaterialResumeDto> purchaseReturnList = new ArrayList<>();
//            List<MaterialResumeDto> purchaseReturn = wmsStockInfoMapper.getPurchaseReturn(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : purchaseReturn) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                purchaseReturnList.add(materialResumeDto);
//            }
//
//            // 其他出库
//            List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
//            List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : otherOutbound) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                otherOutboundList.add(materialResumeDto);
//            }
//
//
//            // 水刺制令单
//            List<MaterialResumeDto> spunlaceOrderList = new ArrayList<>();
//            AjaxResult materialNumber1 = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
//            FeedRecordDetailsDto feedRecordDetailsData1 = JSON.parseObject(JSON.toJSONString(materialNumber1.get("data")), FeedRecordDetailsDto.class);
//            if (feedRecordDetailsData1 != null && feedRecordDetailsData1.getFeedType() != null) {
//                if (feedRecordDetailsData1.getFeedType() == 1) {
//                    MaterialResumeDto materialResumeDto1 = new MaterialResumeDto();
//                    materialResumeDto1.setJobTypeDict("扫码投料");
//                    materialResumeDto1.setDocumentType("水刺制令单");
//                    materialResumeDto1.setConnectDoc(feedRecordDetailsData1.getFeedOrderNumber());
//                    materialResumeDto1.setCreateUser(feedRecordDetailsData1.getCreateBy());
//                    materialResumeDto1.setCreateTime(feedRecordDetailsData1.getCreateTime());
//                    spunlaceOrderList.add(materialResumeDto1);
//                } else {
//                    MaterialResumeDto materialResumeDto2 = new MaterialResumeDto();
//                    materialResumeDto2.setJobTypeDict("扫码投料");
//                    materialResumeDto2.setDocumentType("脱脂制令单");
//                    materialResumeDto2.setConnectDoc(feedRecordDetailsData1.getFeedOrderNumber());
//                    materialResumeDto2.setCreateUser(feedRecordDetailsData1.getCreateBy());
//                    materialResumeDto2.setCreateTime(feedRecordDetailsData1.getCreateTime());
//                    spunlaceOrderList.add(materialResumeDto2);
//                }
//            }
//
//
////            // 脱脂制令单
////            List<MaterialResumeDto> feedRecordDetailsDataList = new ArrayList<>();
////            AjaxResult materialNumber = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
////            FeedRecordDetailsDto feedRecordDetailsData = JSON.parseObject(JSON.toJSONString(materialNumber.get("data")), FeedRecordDetailsDto.class);
////
////            if (feedRecordDetailsData.getFeedType() == 2) {
////                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
////                materialResumeDto.setJobTypeDict("扫码投料");
////                materialResumeDto.setDocumentType("水刺制令单");
////                materialResumeDto.setConnectDoc(feedRecordDetailsData.getFeedOrderNumber());
////                materialResumeDto.setCreateUser(feedRecordDetailsData.getCreateBy());
////                materialResumeDto.setCreateTime(feedRecordDetailsData.getCreateTime());
////                feedRecordDetailsDataList.add(materialResumeDto);
////            }
//
//            // 调拨单信息
//            List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
//            AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
//            if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("调拨管理");
//                materialResumeDto.setDocumentType("调拨单信息");
//                materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
//                materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
//                materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
//                allotManagementDetailInfoList.add(materialResumeDto);
//            }
//
//            // 盘点单信息
//            List<MaterialResumeDto> checkDetailList = new ArrayList<>();
//            List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
//            for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
//                if (checkManagmentMaterialDto.getCheckDoc() != null) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("盘点管理");
//                    materialResumeDto.setDocumentType("盘点单信息");
//                    materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
//                    materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
//                    materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
//                    checkDetailList.add(materialResumeDto);
//                }
//            }
//
//
//            list.addAll(materialResumeDtoList);
//            list.addAll(purchasePersonalDetailsList);
//            list.addAll(productionReturnPersonalDetailsList);
//            list.addAll(otherWarehousingPersonalDetailsList);
//            list.addAll(pickingPersonalDetailsList);
//            list.addAll(outsourcingShipmentPersonalList);
//            list.addAll(purchaseReturnList);
//            list.addAll(otherOutboundList);
//            list.addAll(spunlaceOrderList);
////            list.addAll(feedRecordDetailsDataList);
//            list.addAll(allotManagementDetailInfoList);
//            list.addAll(checkDetailList);
//        }
//        // 当类型为半成品
//        if (wsiCategory == 3) {
//
//            // 生产退料
//            List<MaterialResumeDto> productionReturnPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> productionReturnPersonalDetails = wmsStockInfoMapper.getProductionReturnPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : productionReturnPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                productionReturnPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 完工入库
//            List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
//            List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : wipCompletionList) {
//                materialResumeDto.setJobTypeDict("扫码/批次入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                wipCompletionInfoList.add(materialResumeDto);
//            }
//
//            // 委外入库
//            List<MaterialResumeDto> subcontractReceiptListList = new ArrayList<>();
//            List<MaterialResumeDto> subcontractReceiptList = wmsStockInfoMapper.getSubcontractReceiptList(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : subcontractReceiptList) {
//                materialResumeDto.setJobTypeDict("扫码/批次入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                subcontractReceiptListList.add(materialResumeDto);
//            }
//
//            // 来料打印
//            List<MaterialResumeDto> materialResumeDtoList = new ArrayList<>();
//            List<MaterialResumeDto> materialResumeDtos = wmsStockInfoMapper.getIncomingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : materialResumeDtos) {
//                materialResumeDto.setJobTypeDict("委外打印");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                materialResumeDtoList.add(materialResumeDto);
//            }
//
//            // 其他入库
//            List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码入库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                otherWarehousingPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 生产领料
//            List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
//            List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                pickingPersonalDetailsList.add(materialResumeDto);
//            }
//
//            // 返工出库
//            List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
//            List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                pickingCompleteList.add(materialResumeDto);
//            }
//
//            // 委外发货
//            List<MaterialResumeDto> outsourcingShipmentPersonalList = new ArrayList<>();
//            List<MaterialResumeDto> outsourcingShipmentPersonal = wmsStockInfoMapper.getOutsourcingShipmentPersonal(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : outsourcingShipmentPersonal) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                outsourcingShipmentPersonalList.add(materialResumeDto);
//            }
//
//            // 委外退货
//            List<MaterialResumeDto> pickingReturnsList = new ArrayList<>();
//            List<MaterialResumeDto> pickingReturnsInfoList = wmsStockInfoMapper.getPickingReturnsInfoList(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : pickingReturnsInfoList) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                pickingReturnsList.add(materialResumeDto);
//            }
//
//            // 其他出库
//            List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
//            List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
//            for (MaterialResumeDto materialResumeDto : otherOutbound) {
//                materialResumeDto.setJobTypeDict("扫码/批次出库");
//                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                otherOutboundList.add(materialResumeDto);
//            }
//
//
////            // 水刺制令单
////            List<MaterialResumeDto> spunlaceOrderList = new ArrayList<>();
////            // TODO 修改库存日志表
////            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, wsiMaterialNumber));
////            // 查询投料类型
////            AjaxResult ajaxResult = feignProductionService.selectSpunlaceOrderInfo(wmsStockInfo.getWsiConnectNum());
////            if (ajaxResult != null) {
////                List<MaterialResumeDto> data = JSON.parseArray(JSON.toJSONString(ajaxResult.get("data")), MaterialResumeDto.class);
////                for (MaterialResumeDto materialResumeDto : data) {
////                    if (materialResumeDto.getDocumentType().equals("1")) {
////                        AjaxResult ajaxResult1 = feignProductionService.selectDocumentStatusInfo(wmsStockInfo.getWsiConnectNum());
////                        SpunlaceOrder data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), SpunlaceOrder.class);
////                        materialResumeDto.setJobTypeDict("扫码投料");
////                        materialResumeDto.setDocumentType(data1.getDocumentStatus());
////                        materialResumeDto.setConnectDoc(materialResumeDto.getConnectDoc());
////                        materialResumeDto.setCreateUser(materialResumeDto.getCreateUser());
////                        materialResumeDto.setCreateTime(materialResumeDto.getCreateTime());
////                        spunlaceOrderList.add(materialResumeDto);
////                    }
////                }
////            }
//
//
////            if (wmsStockInfo == null) {
////                OutboundLog outboundLog = outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, wsiMaterialNumber));
////                // 查询投料类型
////                AjaxResult ajaxResult1 = feignProductionService.selectSpunlaceOrderInfo(outboundLog.getWsiConnectNum());
////                List<MaterialResumeDto> data1 = JSON.parseArray(JSON.toJSONString(ajaxResult1.get("data")), MaterialResumeDto.class);
////                for (MaterialResumeDto materialResumeDto : data1) {
////                    if (materialResumeDto.getDocumentType().equals("1")) {
////                        AjaxResult ajaxResult2 = feignProductionService.selectDocumentStatusInfo(outboundLog.getWsiConnectNum());
////                        SpunlaceOrder data2 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), SpunlaceOrder.class);
////                        materialResumeDto.setJobTypeDict("扫码投料");
////                        materialResumeDto.setDocumentType(data2.getDocumentStatus());
////                        materialResumeDto.setConnectDoc(materialResumeDto.getConnectDoc());
////                        materialResumeDto.setCreateUser(materialResumeDto.getCreateUser());
////                        materialResumeDto.setCreateTime(materialResumeDto.getCreateTime());
////                        spunlaceOrderList.add(materialResumeDto);
////                    }
////                }
////            }
//
//
////            List<MaterialResumeDto> detailListMaterialNumber = new ArrayList<>();
////            AjaxResult ajaxResult3 = feignProductionService.selectDetailListMaterialNumber(wsiMaterialNumber);
////            DegreasOutputDetailDto data3 = JSON.parseObject(JSON.toJSONString(ajaxResult3.get("data")), DegreasOutputDetailDto.class);
////            if (data3!=null) {
////                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
////                materialResumeDto.setJobTypeDict("扫码投料");
////                materialResumeDto.setDocumentType("水刺制令单");
////                materialResumeDto.setConnectDoc(data3.getDegreasOrderNumber());
////                materialResumeDto.setCreateUser(data3.getCreateBy());
////                materialResumeDto.setCreateTime(data3.getCreateTime());
////                detailListMaterialNumber.add(materialResumeDto);
////            }
//
//            // 投料
//            List<MaterialResumeDto> feedRecordDetailsDataList = new ArrayList<>();
//            AjaxResult materialNumber = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
//            FeedRecordDetailsDto feedRecordDetailsData = JSON.parseObject(JSON.toJSONString(materialNumber.get("data")), FeedRecordDetailsDto.class);
//            if (feedRecordDetailsData != null && feedRecordDetailsData.getFeedType() == 1) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("扫码投料");
//                materialResumeDto.setDocumentType("水刺制令单");
//                materialResumeDto.setConnectDoc(feedRecordDetailsData.getFeedOrderNumber());
//                materialResumeDto.setCreateUser(feedRecordDetailsData.getCreateBy());
//                materialResumeDto.setCreateTime(feedRecordDetailsData.getCreateTime());
//                feedRecordDetailsDataList.add(materialResumeDto);
//            }
//
//
//            // 产出打印
//            List<MaterialResumeDto> degreasOutputDetailList1 = new ArrayList<>();
//            AjaxResult ajaxResult1 = feignProductionService.selectMaterialNumberInfo(wsiMaterialNumber);
//            DegreasOutputDetail DegreasOutputDetailData = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), DegreasOutputDetail.class);
//            if (DegreasOutputDetailData != null) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("产出打印");
//                materialResumeDto.setDocumentType("脱脂制令单");
//                materialResumeDto.setConnectDoc(DegreasOutputDetailData.getDegreasOrderNumber());
//                materialResumeDto.setCreateUser(DegreasOutputDetailData.getCreateBy());
//                materialResumeDto.setCreateTime(DegreasOutputDetailData.getCreateTime());
//                degreasOutputDetailList1.add(materialResumeDto);
//            }
//
//            // 扫描入库
//            List<MaterialResumeDto> degreasOutputDetailList = new ArrayList<>();
//            AjaxResult ajaxResult2 = feignProductionService.selectMaterialNumberInfo(wsiMaterialNumber);
//            DegreasOutputDetail data1 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), DegreasOutputDetail.class);
//            if (data1 != null && data1.getStatus() == 2) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("扫描入库");
//                materialResumeDto.setDocumentType("脱脂制令单");
//                materialResumeDto.setConnectDoc(data1.getDegreasOrderNumber());
//                materialResumeDto.setCreateUser(data1.getOperator());
//                materialResumeDto.setCreateTime(data1.getOutputTime());
//                degreasOutputDetailList.add(materialResumeDto);
//            }
//
//            // 调拨单信息
//            List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
//            AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
//            if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("调拨管理");
//                materialResumeDto.setDocumentType("调拨单信息");
//                materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
//                materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
//                materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
//                allotManagementDetailInfoList.add(materialResumeDto);
//            }
//
//            // 盘点单信息
//            List<MaterialResumeDto> checkDetailList = new ArrayList<>();
//            List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
//            for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
//                if (checkManagmentMaterialDto.getCheckDoc() != null) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("盘点管理");
//                    materialResumeDto.setDocumentType("盘点单信息");
//                    materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
//                    materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
//                    materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
//                    checkDetailList.add(materialResumeDto);
//                }
//            }
//
//            // 生产退料
//            list.addAll(productionReturnPersonalDetailsList);
//            // 完工入库
//            list.addAll(wipCompletionInfoList);
//            // 委外入库
//            list.addAll(subcontractReceiptListList);
//            // 来料打印
//            list.addAll(materialResumeDtoList);
//            // 其他入库
//            list.addAll(otherWarehousingPersonalDetailsList);
//            // 生产领料
//            list.addAll(pickingPersonalDetailsList);
//            // 返工出库
//            list.addAll(pickingCompleteList);
//            // 委外发货
//            list.addAll(outsourcingShipmentPersonalList);
//            // 委外退货
//            list.addAll(pickingReturnsList);
//            // 其他出库
//            list.addAll(otherOutboundList);
////            // 水刺制令单
////            list.addAll(spunlaceOrderList);
//            // 产出打印
//            list.addAll(degreasOutputDetailList1);
//            // 扫描入库
//            list.addAll(degreasOutputDetailList);
////            // 扫描入库
////            list.addAll(detailListMaterialNumber);
//            list.addAll(feedRecordDetailsDataList);
//            list.addAll(allotManagementDetailInfoList);
//            list.addAll(checkDetailList);
//        }
//        return list;
//    }
//
//    /**
//     * 产品追溯基础信息（feign调用 产品追溯页面使用）
//     *
//     * @param codingType
//     * @param wsiMaterialNumber
//     * @return
//     */
//    @Override
//    public List<ProductTraceabilityDto> getProductTraceabilityList(String codingType, String wsiMaterialNumber) {
//
//        // 类别
//        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
//        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 物料等级
//        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
//        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 库存状态
//        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
//        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        // 冻结标识
//        List<SysDictData> freezeInfo = DictUtils.getDictCache("wms_stock_info_freeze_info");
//        Map<String, String> freezeInfoMap = freezeInfo.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//
//        List<ProductTraceabilityDto> list = new ArrayList<>();
//        // 如果是成品
//        if (codingType.equals("1")) {
//            // 库存表
//            ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getProductTraceabilityList(wsiMaterialNumber);
//
//            if (productTraceabilityList != null) {
//                AjaxResult ajaxResult = feignService.selectCodingRulesById(productTraceabilityList.getWsiMaterialType());
//                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
//                productTraceabilityList.setWsiMaterialTypeDict(data.getCodingRules());
//                // 库存状态
//                productTraceabilityList.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(productTraceabilityList.getWsiMaterialStatus()));
//                list.add(productTraceabilityList);
//            } else {
//                ProductTraceabilityDto productTraceabilityListLog = wmsStockInfoMapper.getProductTraceabilityListLog(wsiMaterialNumber);
//                AjaxResult ajaxResult = feignService.selectCodingRulesById(productTraceabilityListLog.getWsiMaterialType());
//                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
//                productTraceabilityListLog.setWsiMaterialTypeDict(data.getCodingRules());
//                productTraceabilityListLog.setWsiMaterialStatusDict("已出库");
//                list.add(productTraceabilityListLog);
//            }
//        }
//
//        // 如果是母卷
//        if (codingType.equals("2")) {
//            AjaxResult ajaxResult = feignProductionService.selectSpunlaceDetailList(wsiMaterialNumber);
//            SpunlaceOutputDetailDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), SpunlaceOutputDetailDto.class);
//            if (data != null) {
//                // 仓库表
//                ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getProductTraceabilityList(wsiMaterialNumber);
//                if (productTraceabilityList != null) {
//                    AjaxResult ajaxResult1 = feignService.selectCodingRulesById(productTraceabilityList.getWsiMaterialType());
//                    MaterialCodingDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), MaterialCodingDto.class);
//                    productTraceabilityList.setWsiMaterialTypeDict(data1.getCodingRules());
//                    // 库存状态
//                    productTraceabilityList.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(productTraceabilityList.getWsiMaterialStatus()));
//                    list.add(productTraceabilityList);
//
//                }
//                // 仓库日志表
//                ProductTraceabilityDto productTraceabilityListLog = wmsStockInfoMapper.getProductTraceabilityListLog(wsiMaterialNumber);
//                if (productTraceabilityListLog != null) {
//                    AjaxResult ajaxResult2 = feignService.selectCodingRulesById(productTraceabilityListLog.getWsiMaterialType());
//                    MaterialCodingDto data2 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), MaterialCodingDto.class);
//                    productTraceabilityListLog.setWsiMaterialTypeDict(data2.getCodingRules());
//                    productTraceabilityListLog.setWsiMaterialStatusDict("已出库");
//                    list.add(productTraceabilityListLog);
//                } else {
//                    ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
//                    // 批次
//                    productTraceabilityDto.setWsiMaterialBatch(data.getProductionBatch());
//                    // 净重
//                    productTraceabilityDto.setWsiNetWeight(data.getNetWeight());
//                    // 幅宽
//                    productTraceabilityDto.setWsiWidth(data.getNetWeight());
//                    // 卷径
//                    productTraceabilityDto.setWsiDiameter(Double.valueOf(data.getRollingDiameter()));
//                    // 入库时间
//                    productTraceabilityDto.setWsiReveiveTime(data.getStockDate());
//                    list.add(productTraceabilityDto);
//                }
//            }
//        }
//
//        // 如果是小卷
//        if (codingType.equals("3")) {
//
//
//            AjaxResult ajaxResult1 = feignProductionService.getTraceabilityRollInfo(wsiMaterialNumber);
//            RollPackingHistoryDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), RollPackingHistoryDto.class);
//            if (data1 != null && data1.getSmallVolumeNumber() != null) {
//                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data1.getMaterialCode()));
//                ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
//                // 产品编码
//                productTraceabilityDto.setWsiMaterialCode(data1.getMaterialCode());
//                // 幅宽
//                productTraceabilityDto.setWsiWidth(Double.valueOf(data1.getWidth()));
//                // 产品类别
//                productTraceabilityDto.setWsiMaterialType(String.valueOf(publicGoods.getMaterialType()));
//                // 产品名称
//                productTraceabilityDto.setMaterialName(publicGoods.getMaterialName());
//                // 产品规格
//                productTraceabilityDto.setMaterialSpec(publicGoods.getMaterialSpec());
//                list.add(productTraceabilityDto);
//            } else {
//                AjaxResult ajaxResult = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
//                RollPackingHistoryDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), RollPackingHistoryDto.class);
//                if (data != null) {
//                    PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data.getMaterialCode()));
//                    ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
//                    // 产品编码
//                    productTraceabilityDto.setWsiMaterialCode(data.getMaterialCode());
//                    // 幅宽
//                    productTraceabilityDto.setWsiWidth(Double.valueOf(data.getWidth()));
//                    // 产品类别
//                    productTraceabilityDto.setWsiMaterialType(String.valueOf(publicGoods.getMaterialType()));
//                    // 产品名称
//                    productTraceabilityDto.setMaterialName(publicGoods.getMaterialName());
//                    // 产品规格
//                    productTraceabilityDto.setMaterialSpec(publicGoods.getMaterialSpec());
//                    list.add(productTraceabilityDto);
//                }
//            }
//        }
//
//        // 数据字典
//        for (ProductTraceabilityDto productTraceabilityDto : list) {
//            productTraceabilityDto.setWsiCategoryDict(qualityCategoryMap.get(productTraceabilityDto.getWsiCategory()));
//            productTraceabilityDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(productTraceabilityDto.getWsiMaterialGrade()));
////            productTraceabilityDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(productTraceabilityDto.getWsiMaterialStatus()));
//            productTraceabilityDto.setWsiFreezeInfoDict(freezeInfoMap.get(productTraceabilityDto.getWsiFreezeInfo()));
//        }
//
//        return list;
//    }
//
//    /**
//     * 产品履历
//     *
//     * @param codingType
//     * @param wsiMaterialNumber
//     * @return
//     */
//    @Override
//    public List<MaterialResumeDto> getProductPersonalDetails(String codingType, String wsiMaterialNumber) {
//
//        List<MaterialResumeDto> list = new ArrayList<>();
//
//        // 1、如果是成品
//        if (codingType.equals("1")) {
//            // 获取产品号码的物料编码
//            ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getWsiMaterialNumberList(wsiMaterialNumber);
//            if (productTraceabilityList != null) {
//                if (productTraceabilityList.getWsiCategory().equals("4")) {
//
//                    // 完工入库
//                    List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
//                    List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : wipCompletionList) {
//                        materialResumeDto.setJobTypeDict("扫码/批次入库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        wipCompletionInfoList.add(materialResumeDto);
//                    }
//
//                    // 销售退货
//                    List<MaterialResumeDto> salesReturnList = new ArrayList<>();
//                    List<MaterialResumeDto> salesReturnInfoList = wmsStockInfoMapper.getSalesReturnInfoList(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : salesReturnInfoList) {
//                        materialResumeDto.setJobTypeDict("扫码入库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        salesReturnList.add(materialResumeDto);
//                    }
//
//                    // 其他入库
//                    List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
//                    List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
//                        materialResumeDto.setJobTypeDict("扫码入库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        otherWarehousingPersonalDetailsList.add(materialResumeDto);
//                    }
//
//                    // 销售发货
//                    List<MaterialResumeDto> salesShipmentList = new ArrayList<>();
//                    List<MaterialResumeDto> salesShipmentInfoList = wmsStockInfoMapper.getSalesShipmentInfoList(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : salesShipmentInfoList) {
//                        materialResumeDto.setJobTypeDict("扫码/批次出库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        salesShipmentList.add(materialResumeDto);
//                    }
//
//                    // 返工出库
//                    List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
//                    List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
//                        materialResumeDto.setJobTypeDict("扫码/批次出库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        pickingCompleteList.add(materialResumeDto);
//                    }
//
//                    // 其他出库
//                    List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
//                    List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
//                    for (MaterialResumeDto materialResumeDto : otherOutbound) {
//                        materialResumeDto.setJobTypeDict("扫码/批次出库");
//                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                        otherOutboundList.add(materialResumeDto);
//                    }
//
//                    // 成品称重
//                    List<MaterialResumeDto> weighingFinishedList = new ArrayList<>();
//                    AjaxResult weighingFinishedData = feignProductionService.getWeighingFinishedData(wsiMaterialNumber);
//                    WeighingFinishedMaterialProductDto data = JSON.parseObject(JSON.toJSONString(weighingFinishedData.get("data")), WeighingFinishedMaterialProductDto.class);
//                    if (data.getWarehousingBy() != null) {
//                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                        materialResumeDto.setJobTypeDict("扫码入库");
//                        materialResumeDto.setCreateUser(data.getWarehousingBy());
//                        materialResumeDto.setCreateTime(data.getWarehousingTime());
//                        weighingFinishedList.add(materialResumeDto);
//                    }
//
//                    // 扫描入库
//                    List<MaterialResumeDto> spunlaceDetailList2 = new ArrayList<>();
//                    AjaxResult spunlaceDetailList = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
//                    SpunlaceOutputDetailDto dataList = JSON.parseObject(JSON.toJSONString(spunlaceDetailList.get("data")), SpunlaceOutputDetailDto.class);
//                    if (dataList.getCreateMan() != null) {
//                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                        materialResumeDto.setConnectDoc(dataList.getSpunlaceOrderNumber());
//                        materialResumeDto.setCreateUser(dataList.getCreateMan());
//                        materialResumeDto.setCreateTime(dataList.getCreateTime());
//                        spunlaceDetailList2.add(materialResumeDto);
//                    }
//
//                    // 调拨单信息
//                    List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
//                    AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
//                    if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
//                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                        materialResumeDto.setJobTypeDict("调拨管理");
//                        materialResumeDto.setDocumentType("调拨单信息");
//                        materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
//                        materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
//                        materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
//                        allotManagementDetailInfoList.add(materialResumeDto);
//                    }
//
//                    // 盘点单信息
//                    List<MaterialResumeDto> checkDetailList = new ArrayList<>();
//                    List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
//                    for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
//                        if (checkManagmentMaterialDto.getCheckDoc() != null) {
//                            MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                            materialResumeDto.setJobTypeDict("盘点管理");
//                            materialResumeDto.setDocumentType("盘点单信息");
//                            materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
//                            materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
//                            materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
//                            checkDetailList.add(materialResumeDto);
//                        }
//                    }
//
//                    // 完工入库
//                    list.addAll(wipCompletionInfoList);
//                    // 销售退货
//                    list.addAll(salesReturnList);
//                    // 其他入库
//                    list.addAll(otherWarehousingPersonalDetailsList);
//                    // 销售发货
//                    list.addAll(salesShipmentList);
//                    // 返工出库
//                    list.addAll(pickingCompleteList);
//                    // 其他出库
//                    list.addAll(otherOutboundList);
//                    // 成品称重
//                    list.addAll(weighingFinishedList);
//                    // 扫描入库
//                    list.addAll(spunlaceDetailList2);
//                    // 调拨单信息
//                    list.addAll(allotManagementDetailInfoList);
//                    // 盘点单信息
//                    list.addAll(checkDetailList);
//                }
//            }
//        }
//        // 2、如果是母卷
//        if (codingType.equals("2")) {
//            AjaxResult cutOrdersDocumentInfo = feignProductionService.getCutOrdersDocumentInfo(wsiMaterialNumber);
//            CutOrdersDocumentDetailDto data = JSON.parseObject(JSON.toJSONString(cutOrdersDocumentInfo.get("data")), CutOrdersDocumentDetailDto.class);
//            if (data != null) {
//                // 完工入库
//                List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
//                List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
//                for (MaterialResumeDto materialResumeDto : wipCompletionList) {
//                    materialResumeDto.setJobTypeDict("扫码/批次入库");
//                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                    wipCompletionInfoList.add(materialResumeDto);
//                }
//
//                // 其他入库
//                List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
//                List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
//                for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
//                    materialResumeDto.setJobTypeDict("扫码入库");
//                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                    otherWarehousingPersonalDetailsList.add(materialResumeDto);
//                }
//
//                // 生产领料
//                List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
//                List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
//                for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
//                    materialResumeDto.setJobTypeDict("扫码/批次出库");
//                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                    pickingPersonalDetailsList.add(materialResumeDto);
//                }
//                // 返工出库
//                List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
//                List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
//                for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
//                    materialResumeDto.setJobTypeDict("扫码/批次出库");
//                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                    pickingCompleteList.add(materialResumeDto);
//                }
//
//                // 其他出库
//                List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
//                List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
//                for (MaterialResumeDto materialResumeDto : otherOutbound) {
//                    materialResumeDto.setJobTypeDict("扫码/批次出库");
//                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
//                    otherOutboundList.add(materialResumeDto);
//                }
//
//                // 水刺制令单 产出打印
//                List<MaterialResumeDto> spunlaceDetailList1 = new ArrayList<>();
//                AjaxResult spunlaceDetail = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
//                SpunlaceOutputDetailDto data1 = JSON.parseObject(JSON.toJSONString(spunlaceDetail.get("data")), SpunlaceOutputDetailDto.class);
//                if (data1.getCreateMan() != null) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("产出打印");
//                    materialResumeDto.setDocumentType("水刺制令单");
//                    materialResumeDto.setConnectDoc(data1.getSpunlaceOrderNumber());
//                    materialResumeDto.setCreateUser(data1.getCreateMan());
//                    materialResumeDto.setCreateTime(data1.getCreateTime());
//                    spunlaceDetailList1.add(materialResumeDto);
//                }
//
//                // 水刺制令单 扫描入库
//                List<MaterialResumeDto> spunlaceDetailList2 = new ArrayList<>();
//                AjaxResult spunlaceDetailList = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
//                SpunlaceOutputDetailDto dataList = JSON.parseObject(JSON.toJSONString(spunlaceDetailList.get("data")), SpunlaceOutputDetailDto.class);
//                if (dataList.getCreateMan() != null && dataList.getProductionStatus().equals("2")) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("扫描入库");
//                    materialResumeDto.setDocumentType("水刺制令单");
//                    materialResumeDto.setConnectDoc(dataList.getSpunlaceOrderNumber());
//                    materialResumeDto.setCreateUser(dataList.getCreateMan());
//                    materialResumeDto.setCreateTime(dataList.getCreateTime());
//                    spunlaceDetailList2.add(materialResumeDto);
//                }
//
//                // 验布
//                List<MaterialResumeDto> ClothInspectionDetailList = new ArrayList<>();
//                AjaxResult list1 = feignProductionService.selectDetailLisMasterVolumeNumber(wsiMaterialNumber);
//                List<ClothInspectionDetailDto> data2 = JSON.parseArray(JSON.toJSONString(list1.get("data")), ClothInspectionDetailDto.class);
//                for (ClothInspectionDetailDto clothInspectionDetailDto : data2) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("验布");
//                    materialResumeDto.setCreateUser(clothInspectionDetailDto.getClothInspectionBy());
//                    materialResumeDto.setCreateTime(clothInspectionDetailDto.getClothInspectionTime());
//                    ClothInspectionDetailList.add(materialResumeDto);
//                }
//
//                // 分切
//                List<MaterialResumeDto> CutOrdersDocumentList = new ArrayList<>();
//                AjaxResult CutOrdersList = feignProductionService.getCutOrdersDocumentInfo(wsiMaterialNumber);
//                CutOrdersDocumentDetailDto data3 = JSON.parseObject(JSON.toJSONString(CutOrdersList.get("data")), CutOrdersDocumentDetailDto.class);
//                if (data3.getSlittBy() != null && data3.getSlittingStatus().equals("2")) {
//                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                    materialResumeDto.setJobTypeDict("分切");
//                    materialResumeDto.setDocumentType("分切制令单");
//                    materialResumeDto.setConnectDoc(data3.getDocumentNum());
//                    materialResumeDto.setCreateUser(data3.getSlittBy());
//                    materialResumeDto.setCreateTime(data3.getSlittTime());
//                    CutOrdersDocumentList.add(materialResumeDto);
//                }
//
//                // 分卷
//
//                list.addAll(wipCompletionInfoList);
//                list.addAll(otherWarehousingPersonalDetailsList);
//                list.addAll(pickingPersonalDetailsList);
//                list.addAll(pickingCompleteList);
//                list.addAll(otherOutboundList);
//                list.addAll(spunlaceDetailList1);
//                list.addAll(spunlaceDetailList2);
//                list.addAll(ClothInspectionDetailList);
//                list.addAll(CutOrdersDocumentList);
//
//            }
//        }
//
//
//        //3、如果是小卷
//        if (codingType.equals("3")) {
//            // 小卷打包
//            AjaxResult ajaxResult = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
//            RollPackingHistoryDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), RollPackingHistoryDto.class);
//            if (data != null && data.getCreateTime() != null) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("小卷打包");
//                materialResumeDto.setCreateUser(data.getFeeder());
//                materialResumeDto.setCreateTime(data.getCreateTime());
//                list.add(materialResumeDto);
//            }
//        }
//
//        return list;
//    }

    /**
     * 库存汇总
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<InventorySummaryDto> getInventorySummaryList(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) {
        //单位map集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();
        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        // 类别
        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        Page<InventorySummaryDto> pageList = wmsStockInfoMapper.getInventorySummaryList(wmsStockInfoVo, pageQuery.build());
        List<InventorySummaryDto> list = pageList.getRecords();
        // 获取类别名称
        for (InventorySummaryDto inventorySummaryDto : list) {
            //SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(inventorySummaryDto.getMaterialType());
            inventorySummaryDto.setMaterialTypeDict(inventorySummaryDto.getCategoryName());

            // 类别字典
            inventorySummaryDto.setWsiCategoryDict(qualityCategoryMap.get(inventorySummaryDto.getCategoryType()));
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + inventorySummaryDto.getTenantId(), String.valueOf(inventorySummaryDto.getMaterialId()));
            inventorySummaryDto.setAuxiliaryAttribute(statsArray);
            //单位
            if (unitByCodeToMap.get(inventorySummaryDto.getMaterialUnit()) != null) {
                inventorySummaryDto.setMaterialUnitDict(unitByCodeToMap.get(inventorySummaryDto.getMaterialUnit()).getUnitName());
            }
        }
        return TableDataInfo.build(pageList);
    }

    /**
     * 原料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<DetailsMaterialsDto> getInventoryMaterialDetailed(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) throws Exception {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        Page<DetailsMaterialsDto> pageList = wmsStockInfoMapper.getInventoryMaterialDetailed(wmsStockInfoVo, pageQuery.build());
        List<DetailsMaterialsDto> list = pageList.getRecords();
        for (DetailsMaterialsDto detailsMaterialsDto : list) {
           // SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            //单位
            if(detailsMaterialsDto.getConvertUnit() != null){
                detailsMaterialsDto.setMaterialUnitDict(unitByCodeToMap.get(detailsMaterialsDto.getConvertUnit()).getUnitName());
            }

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            detailsMaterialsDto.setMaterialTypeDict(detailsMaterialsDto.getCategoryName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + detailsMaterialsDto.getTenantId(), String.valueOf(detailsMaterialsDto.getMaterialId()));
            detailsMaterialsDto.setAuxiliaryAttribute(statsArray);
            //单位转换
            String s = unitUtil.unitC(detailsMaterialsDto.getWsiMaterialCode(),
                String.valueOf(detailsMaterialsDto.getWsiNetWeight()),
                detailsMaterialsDto.getMaterialId(),
                unitByCodeToMap.get(detailsMaterialsDto.getMaterialUnit()).getUnitName());
            detailsMaterialsDto.setUnitConversion(s);
        }
        return TableDataInfo.build(pageList);
    }

    /**
     * 辅料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<DetailsMaterialsDto> getInventoryAccessoriesDetailed(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) throws Exception {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        Page<DetailsMaterialsDto> pageList = wmsStockInfoMapper.getInventoryAccessoriesDetailed(wmsStockInfoVo, pageQuery.build());
        List<DetailsMaterialsDto> inventoryAccessoriesDetailed = pageList.getRecords();
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryAccessoriesDetailed) {
            //SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            //单位
            if(detailsMaterialsDto.getConvertUnit() != null){
                detailsMaterialsDto.setMaterialUnitDict(unitByCodeToMap.get(detailsMaterialsDto.getConvertUnit()).getUnitName());
            }
            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            detailsMaterialsDto.setMaterialTypeDict(detailsMaterialsDto.getCategoryName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + detailsMaterialsDto.getTenantId(), String.valueOf(detailsMaterialsDto.getMaterialId()));
            detailsMaterialsDto.setAuxiliaryAttribute(statsArray);
            //单位转换
            String s = unitUtil.unitC(detailsMaterialsDto.getWsiMaterialCode(),
                String.valueOf(detailsMaterialsDto.getWsiNetWeight()),
                detailsMaterialsDto.getMaterialId(),
                unitByCodeToMap.get(detailsMaterialsDto.getMaterialUnit()).getUnitName());
            detailsMaterialsDto.setUnitConversion(s);
        }
        return TableDataInfo.build(pageList);
    }

    /**
     * 成品明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<DetailsMaterialsDto> getInventoryFinishProductDetailed(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) throws Exception {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        Page<DetailsMaterialsDto> pageList = wmsStockInfoMapper.getInventoryFinishProductDetailed(wmsStockInfoVo, pageQuery.build());
        List<DetailsMaterialsDto> inventoryFinishProductDetailed = pageList.getRecords();
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryFinishProductDetailed) {
           // SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            //单位
            if(detailsMaterialsDto.getConvertUnit() != null){
                detailsMaterialsDto.setMaterialUnitDict(unitByCodeToMap.get(detailsMaterialsDto.getConvertUnit()).getUnitName());
            }
            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(detailsMaterialsDto.getCategoryName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + detailsMaterialsDto.getTenantId(), String.valueOf(detailsMaterialsDto.getMaterialId()));
            detailsMaterialsDto.setAuxiliaryAttribute(statsArray);
            //单位转换
            String s = unitUtil.unitC(detailsMaterialsDto.getWsiMaterialCode(),
                String.valueOf(detailsMaterialsDto.getWsiNetWeight()),
                detailsMaterialsDto.getMaterialId(),
                unitByCodeToMap.get(detailsMaterialsDto.getMaterialUnit()).getUnitName());
            detailsMaterialsDto.setUnitConversion(s);
        }
        return TableDataInfo.build(pageList);
    }

    /**
     * 半成品明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<DetailsMaterialsDto> getInventoryMaterialHalfDetailed(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) throws Exception {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();
        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        Page<DetailsMaterialsDto> pageList = wmsStockInfoMapper.getInventoryMaterialHalfDetailed(wmsStockInfoVo, pageQuery.build());
        List<DetailsMaterialsDto> inventoryMaterialHalfDetailed = pageList.getRecords();
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryMaterialHalfDetailed) {
            //SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));

            //单位
            if(detailsMaterialsDto.getConvertUnit() != null){
                detailsMaterialsDto.setMaterialUnitDict(unitByCodeToMap.get(detailsMaterialsDto.getConvertUnit()).getUnitName());
            }
            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(detailsMaterialsDto.getCategoryName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + detailsMaterialsDto.getTenantId(), String.valueOf(detailsMaterialsDto.getMaterialId()));
            detailsMaterialsDto.setAuxiliaryAttribute(statsArray);
            //单位转换
            String s = unitUtil.unitC(detailsMaterialsDto.getWsiMaterialCode(),
                String.valueOf(detailsMaterialsDto.getWsiNetWeight()),
                detailsMaterialsDto.getMaterialId(),
                unitByCodeToMap.get(detailsMaterialsDto.getMaterialUnit()).getUnitName());
            detailsMaterialsDto.setUnitConversion(s);
        }

        return TableDataInfo.build(pageList);
    }

    /**
     * 废料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public TableDataInfo<DetailsMaterialsDto> getInventoryWasteDetailed(WmsStockInfoVo wmsStockInfoVo, PageQuery pageQuery) throws Exception {
        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        //单位集合
        Map<String, MaterialUnitDto> unitByCodeToMap = remoteUnitService.getUnitByCodeToMap();
        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        Page<DetailsMaterialsDto> pageList = wmsStockInfoMapper.getInventoryWasteDetailed(wmsStockInfoVo, pageQuery.build());
        List<DetailsMaterialsDto> inventoryWasteDetailed = pageList.getRecords();
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryWasteDetailed) {

            //SysApiMaterialCoding sysApiMaterialCoding = remoteMaterialService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));

            //单位
            if(detailsMaterialsDto.getConvertUnit() != null){
                detailsMaterialsDto.setMaterialUnitDict(unitByCodeToMap.get(detailsMaterialsDto.getConvertUnit()).getUnitName());
            }
            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(detailsMaterialsDto.getCategoryName());
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + detailsMaterialsDto.getTenantId(), String.valueOf(detailsMaterialsDto.getMaterialId()));
            detailsMaterialsDto.setAuxiliaryAttribute(statsArray);
            //单位转换
            String s = unitUtil.unitC(detailsMaterialsDto.getWsiMaterialCode(),
                String.valueOf(detailsMaterialsDto.getWsiNetWeight()),
                detailsMaterialsDto.getMaterialId(),
                unitByCodeToMap.get(detailsMaterialsDto.getMaterialUnit()).getUnitName());
            detailsMaterialsDto.setUnitConversion(s);
        }

        return TableDataInfo.build(pageList);
    }


    /**
     * 委外发货新增物料汇总信息
     *
     * @param outsourceSumVo
     * @return
     */
    @Override
    public TableDataInfo<OutsourceSumDto> outsourceSum(OutsourceSumVo outsourceSumVo, PageQuery pageQuery) {
        Page<OutsourceSumDto> list = wmsStockInfoMapper.getOutsourceStock(pageQuery.build(), outsourceSumVo);
        for (OutsourceSumDto outsourceSumDto : list.getRecords()) {

            if (outsourceSumDto.getMaterialUnit() != null) {
                String unitName = remoteUnitService.getUnitDataByCode(outsourceSumDto.getMaterialUnit()).getData().getUnitName();
                outsourceSumDto.setMaterialUnitDict(unitName);
            }
            //根据字典查出单位
            if (outsourceSumDto.getMaterialMoreUnit() != null) {
                String unitName = remoteUnitService.getUnitDataByCode(outsourceSumDto.getMaterialMoreUnit()).getData().getUnitName();
                outsourceSumDto.setMaterialUnitDict(unitName);
            }
        }
        return TableDataInfo.build();
    }


    /**
     * 首页工作台成品库存金额
     */
    @Override
    public List<FinishAmountDto> getFinishAmountList() {

        return wmsStockInfoMapper.getFinishAmountList();
    }

    /**
     * 首页工作台原料库存金额
     */
    @Override
    public List<FinishAmountDto> getRawAmount() {
        return wmsStockInfoMapper.getRawAmountList();
    }
//
//    /**
//     * 根据母卷号码删除仓库数据（fegin调用）
//     *
//     * @param masterVolumeNum
//     */
//    @Override
//    public void deleteByMasterVolumeNum(String masterVolumeNum) {
//        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, masterVolumeNum));
//        wmsStockInfoMapper.deleteById(wmsStockInfo);
//    }
//
//    /**
//     * 根据母卷号码查询母卷
//     *
//     * @param wsiMaterialNumber
//     * @return
//     */
//    @Override
//    public OutboundLog selectProductStockInfoById(String wsiMaterialNumber) {
//        return outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, wsiMaterialNumber));
//    }
//
//    /**
//     * 品质处理修改对应物料等级
//     *
//     * @param updateGradeVo
//     * @return
//     */
//    @Override
//    public boolean updateMaterialGrade(UpdateGradeVo updateGradeVo) {
//        List<String> materialNumberList = updateGradeVo.getMaterialNumberList();
//        int materialLevel = updateGradeVo.getMaterialLevel();
//        List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));
//
//        for (WmsStockInfo entity : wmsStockInfos) {
//            entity.setWsiMaterialGrade(String.valueOf(materialLevel));
//        }
//        return updateBatchById(wmsStockInfos);
//    }

    /**
     * 消息提醒-最小安全库存
     */
    @Override
    public void maxStock() throws Exception {
        System.out.println("调用进来了");
        //分组查出仓库的物料编码,重量
        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();

        ArrayList<SysWorkbenchMessageVo> workMessageList = new ArrayList<>();

        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();

        //查询消息提醒表
//        List<SysWorkbenchMessage> infoList = remoteWorkbenchMessageService.getInfo("1");
        List<SysWorkbenchMessageResult> infoList = remoteWorkbenchMessageService.getInfo("1");

        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {
            //查询这个物料编码在公共物料表中的最小安全库存
            PublicMaterial publicMaterial = publicMaterialMapper.selectOne(new QueryWrapper<PublicMaterial>().lambda().eq(PublicMaterial::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));

            //通过物料编码查询出告警信息
            String materialCode = wmsStockInfoSumDto.getWsiMaterialCode();
            SysTheAlarmDto alarm = remoteWorkbenchMessageService.getAlarm(materialCode, "1");

            if (alarm != null) {

                //如果库存重量小余最小安全库存，则提醒
                if (Double.parseDouble(wmsStockInfoSumDto.getStockNum()) < publicMaterial.getMinInventory()) {


                    MessageRemindDto messageRemindDto = new MessageRemindDto();

                    String message = "物料编码:" + wmsStockInfoSumDto.getWsiMaterialCode() + "物料名称:" + wmsStockInfoSumDto.getWsiMaterialName() + "库存不足请及时处理";

                    //获取关结方式
                    String alarmNexus = alarm.getAlarmNexus();

                    boolean flag = false;

                    if ("1".equals(alarmNexus)) {
                        for (SysWorkbenchMessageResult sysWorkbenchMessage : infoList) {
                            if (message.equals(sysWorkbenchMessage.getMessageContent()) && (wmsStockInfoSumDto.getStockNum() + "").equals(sysWorkbenchMessage.getStock() + "")) {
                                flag = true;
                                break;
                            }
                        }
                    }

                    if (flag) {
                        continue;
                    }

                    messageRemindDto.setModelType(1);
                    messageRemindDto.setMessage(message);

                    //添加告警信息
                    messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                    messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                    messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                    messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                    messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                    messageRemindDto.setMessageType(1);
                    messageRemindDto.setMessageTypeDict("库存告警");
                    messageRemindDto.setTenantId(Long.parseLong(wmsStockInfoSumDto.getTenantId()));

                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    messageRemindDto.setToday(simpleDateFormat.format(new Date()));

                    messageRemindDto.setStock(String.valueOf(wmsStockInfoSumDto.getStockNum()));

                    messageRemindDtoList.add(messageRemindDto);


                    SysWorkbenchMessageVo sysWorkbenchMessageVo = new SysWorkbenchMessageVo();
                    sysWorkbenchMessageVo.setMessageType(1);//库存告警
                    sysWorkbenchMessageVo.setMessageContent(message);
                    sysWorkbenchMessageVo.setWarnTime(new Date());
                    sysWorkbenchMessageVo.setReadMark(2);
                    //sysWorkbenchMessageVo.setUserId();
                    workMessageList.add(sysWorkbenchMessageVo);

                }

            }
        }
        if (messageRemindDtoList.size() != 0) {
            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
        }

        if (workMessageList.size() != 0) {
            //feignService.insertWork(workMessageList);
        }
    }


    /**
     * 批量删除
     *
     * @param list
     * @return
     */
    @Override
    public boolean deleteBatch(List<WmsStockInfo> list) {
        return wmsStockInfoMapper.deleteBatchIds(list) > 0;
    }

//    /**
//     * 消息提醒-保质期告警
//     */
//    @Override
//    public void expirationDate() throws Exception {
//        //分组查出仓库的物料编码,重量
//        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();
//
//        //保质期
//        Map<String, Integer> expirationMap = new HashMap<>();
//
//        //过期提醒
//        Map<String, Integer> reminderMap = new HashMap<>();
//
//        //告警信息
//        Map<String,Object> alarmMap = new HashMap<>();
//
//        //查询消息提醒表
//        List<SysWorkbenchMessage> infoList = feignService.getInfo("2");
//
//        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {
//
//            //如果未配置消息提醒则不提醒
//
//
//            //通过物料编码查出保质期和过期提醒
//            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));
//
//            //保质期
//            expirationMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),publicGoods.getMaterialQuality());
//            //过期提醒
//            reminderMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),publicGoods.getMaterialOverdue());
//
//            //通过物料编码查询出告警信息
//            SysTheAlarmDto alarm = feignService.getAlarm(wmsStockInfoSumDto.getWsiMaterialCode(),"2");
//
//            alarmMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),alarm);
//
//        }
//
//        //查询库存中的所有物料号码
//        List<WmsStockDto> materialNumberList = wmsStockInfoMapper.getMaterialList();
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
//
//        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();
//
//        for (WmsStockDto wmsStockInfo : materialNumberList) {
//            //生产日期
//            Date wsiProducedDate = wmsStockInfo.getWsiProducedDate();
//
//            //如果生产日期不为null
//            SysTheAlarmDto alarm = (SysTheAlarmDto) alarmMap.get(wmsStockInfo.getWsiMaterialCode());
//
//            if (alarm!=null) {
//
//                if (wsiProducedDate != null) {
//
//                    String format = simpleDateFormat.format(wsiProducedDate);
//                    Date date = new Date();
//                    String format1 = simpleDateFormat.format(date);
//
//
//                    int daysBetween = DateUtilss.daysBetween(simpleDateFormat.format(wsiProducedDate), simpleDateFormat.format(new Date()));
//
//                    //如果保质期-复检天数<=当前时间-生产日期
//                    String wsiMaterialCode = wmsStockInfo.getWsiMaterialCode();
//                    Integer integer = expirationMap.get(wsiMaterialCode);
//
//                    Integer integer1 = reminderMap.get(wmsStockInfo.getWsiMaterialCode());
//                    if (expirationMap.get(wmsStockInfo.getWsiMaterialCode())>=daysBetween){
//                    if (expirationMap.get(wmsStockInfo.getWsiMaterialCode()) - reminderMap.get(wmsStockInfo.getWsiMaterialCode()) <= daysBetween) {
//                        //获取过期天数
//                        int exceedTime = expirationMap.get(wmsStockInfo.getWsiMaterialCode()) - daysBetween;
//
//                        //消息
//                        String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "将在" + exceedTime + "天后超期,请及时处理";
//
//                        //获取关结方式
//                        String alarmNexus = alarm.getAlarmNexus();
//
//                        boolean flag = false;
//
//                        if ("1".equals(alarmNexus)) {
//                            for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
//                                if (message.equals(sysWorkbenchMessage.getMessageContent())) {
//                                    flag = true;
//                                    break;
//                                }
//                            }
//                        }
//
//                        if (flag) {
//                            continue;
//                        }
//
//
//                        MessageRemindDto messageRemindDto = new MessageRemindDto();
//
//                        messageRemindDto.setMessage(message);
//                        messageRemindDto.setModelType(1);
//
//
//                        messageRemindDto.setAlarmWay(alarm.getAlarmWay());
//                        messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
//                        messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
//                        messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
//                        messageRemindDto.setUserIds(alarm.getAlarmRoleId());
//                        messageRemindDto.setMessageType(2);
//
//                        messageRemindDto.setMessageTypeDict("保质期告警");
//
//                        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//                        messageRemindDto.setToday(simpleDateFormat1.format(new Date()));
//
//                        messageRemindDtoList.add(messageRemindDto);
//                        //触发提醒，内容为“XX号码、XX名称将在X天后超期，请及时处理”
//
//
//                    } } else {
//                        //消息
//                        String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "已超期,请及时处理";
//
//                        //获取关结方式
//                        String alarmNexus = alarm.getAlarmNexus();
//
//                        boolean flag =false;
//
//                        if ("1".equals(alarmNexus)){
//                            for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
//                                if (message.equals(sysWorkbenchMessage.getMessageContent())){
//                                    flag = true;
//                                    break;
//                                }
//                            }
//                        }
//
//                        if (flag){
//                            continue;
//                        }
//
//                        MessageRemindDto messageRemindDto = new MessageRemindDto();
//
//                        messageRemindDto.setMessage(message);
//                        messageRemindDto.setModelType(1);
//
//                            messageRemindDto.setAlarmWay(alarm.getAlarmWay());
//                            messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
//                            messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
//                            messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
//                            messageRemindDto.setUserIds(alarm.getAlarmRoleId());
//                            messageRemindDto.setMessageType(2);
//
//                        messageRemindDto.setMessageTypeDict("保质期告警");
//
//                        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//                        messageRemindDto.setToday(simpleDateFormat1.format(new Date()));
//
//                        //“XX号码、XX名称已超期，请及时处理”
//                        messageRemindDtoList.add(messageRemindDto);
//
//                    }
//                }
//            }
//        }
//        if (messageRemindDtoList.size()!=0){
//            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
//        }
//    }
//
//    /**
//     * 复检到期提醒
//     * @throws Exception
//     */
//    @Override
//    public void recheck() throws Exception {
//        //分组查出仓库的物料编码,重量
//        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();
//
//        //复检日期
//        HashMap<String, Integer> inspectionMap = new HashMap<>();
//
//        //复检提醒
//        HashMap<String, Integer> reminderMap = new HashMap<>();
//
//        //告警信息
//        Map<String,Object> alarmMap = new HashMap<>();
//
//        //批量消息集合
//        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();
//
//        //查询消息提醒表
//        List<SysWorkbenchMessage> infoList = feignService.getInfo("3");
//
//        //定义集合修改物料号码集合
//        List<UpdateWmsVo> updateWmsVos = new ArrayList<>();
//
//        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {
//
//            //通过物料编码查出复检日期和复检提醒
//            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));
//
//            //复检日期
//            inspectionMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),publicGoods.getMaterialInspection());
//            //复检提醒
//            reminderMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),publicGoods.getMaterialReminder());
//
//            //通过物料编码查询出告警信息
//            SysTheAlarmDto alarm = feignService.getAlarm(wmsStockInfoSumDto.getWsiMaterialCode(),"3");
//
//            alarmMap.put(wmsStockInfoSumDto.getWsiMaterialCode(),alarm);
//
//        }
//
//        //查询库存中的所有物料号码
//        List<WmsStockDto> materialNumberList = wmsStockInfoMapper.getMaterialList();
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
//
//        for (WmsStockDto wmsStockInfo : materialNumberList) {
//
//            if (wmsStockInfo.getWsiMaterialNumber().equals("DC23060705-0268")){
//                System.out.println("111");
//            }
//
//            //入库日期
//            Date wsiProducedDate = wmsStockInfo.getWsiReveiveTime();
//
//            SysTheAlarmDto alarm = (SysTheAlarmDto) alarmMap.get(wmsStockInfo.getWsiMaterialCode());
//
//            if (alarm != null) {
//
//                if (wsiProducedDate != null) {
//
//                    if (wmsStockInfo.getWsiRecheckDate() != null) {
//                        wsiProducedDate = wmsStockInfo.getWsiRecheckDate();
//                    }
//
//                    int daysBetween = DateUtilss.daysBetween(simpleDateFormat.format(wsiProducedDate), simpleDateFormat.format(new Date()));
//
//
//                    //如果复检日期-复检天数<=当前时间-生产日期
//                    if (inspectionMap.get(wmsStockInfo.getWsiMaterialCode()) >= daysBetween) {
//
//                        if (inspectionMap.get(wmsStockInfo.getWsiMaterialCode())-daysBetween<=reminderMap.get(wmsStockInfo.getWsiMaterialCode())) {
//
//                            //获取过期天数
//                            int exceedTime = inspectionMap.get(wmsStockInfo.getWsiMaterialCode()) - daysBetween;
//
//                            //消息
//                            String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "将在" + exceedTime + "天后超期复检,请及时处理";
//
//                            //获取关结方式
//                            String alarmNexus = alarm.getAlarmNexus();
//
//                            boolean flag = false;
//
//                            if ("1".equals(alarmNexus)) {
//                                for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
//                                    if (message.equals(sysWorkbenchMessage.getMessageContent())) {
//                                        flag = true;
//                                        break;
//                                    }
//                                }
//                            }
//
//                            if (flag) {
//                                continue;
//                            }
//
//
//                            MessageRemindDto messageRemindDto = new MessageRemindDto();
//
//                            messageRemindDto.setMessage(message);
//                            messageRemindDto.setModelType(1);
//
//
//                            messageRemindDto.setAlarmWay(alarm.getAlarmWay());
//                            messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
//                            messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
//                            messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
//                            messageRemindDto.setUserIds(alarm.getAlarmRoleId());
//                            messageRemindDto.setMessageType(3);
//
//                            messageRemindDto.setMessageTypeDict("复检告警");
//                            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//                            messageRemindDto.setToday(simpleDateFormat1.format(new Date()));
//
//                            messageRemindDtoList.add(messageRemindDto);
//                            //触发提醒，内容为“XX号码、XX名称将在X天后超期复检，请及时处理”
//
//                        }
//
//                    } else {
//                        //消息
//                        String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "已超期复检，请及时处理";
//
//                        //获取关结方式
//                        String alarmNexus = alarm.getAlarmNexus();
//
//                        boolean flag =false;
//
//                        if ("1".equals(alarmNexus)){
//                            for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
//                                if (message.equals(sysWorkbenchMessage.getMessageContent())){
//                                    flag = true;
//                                    break;
//                                }
//                            }
//                        }
//
//                        if (flag){
//                            continue;
//                        }
//
//
//                        MessageRemindDto messageRemindDto = new MessageRemindDto();
//
//                        messageRemindDto.setMessage(message);
//                        messageRemindDto.setModelType(1);
//
//                            messageRemindDto.setAlarmWay(alarm.getAlarmWay());
//                            messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
//                            messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
//                            messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
//                            messageRemindDto.setMessageType(3);
//                        messageRemindDto.setUserIds(alarm.getAlarmRoleId());
//                        messageRemindDto.setMessageTypeDict("复检告警");
//
//                        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//                        messageRemindDto.setToday(simpleDateFormat1.format(new Date()));
//
//                        messageRemindDtoList.add(messageRemindDto);
//                        //内容为“XX号码、XX名称已超期复检，请及时处理”
//
//                    }
//                }
//            }
//
//        }
//
//        if (messageRemindDtoList.size() != 0) {
//            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
//        }
//
//
//    }

}

